import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
      {
          path: '/index',
          name: 'Index',
          component: () => import('../components/Index.vue'),
          children: [
              { 
                  path: '/pay',
                  name: 'Page1',
                  component: () => import('../components/Pay.vue'),
              },
              { 
                  path: '/roles',
                  name: 'Page2',
                  component: () => import('../components/Roles.vue'),
              },
              { 
                  path: '/users',
                  name: 'Page3',
                  component: () => import('../components/Users.vue'),
              },
              { 
                  path: '/res',
                  name: 'Page4',
                  component: () => import('../components/Resource.vue'),
              },
          ]
      },
      {
          path: '/',
          name: 'Login',
          component: () => import('../components/Login.vue'),
      },
      {
          path: '/test',
          name: 'Test',
          component: () => import('../components/test.vue'),
      },
      {
          path: '/sflogin',
          name: 'SFLogin',
          component: () => import('../components/sflogin.vue'),
      },
      {
          path: '/alioss',
          name: 'AliOss',
          component: () => import('../components/ali_oss.vue'),
      },
      {
          path: '/face',
          name: 'Face',
          component: () => import('../components/face.vue'),
      },
      {
          path: '/search',
          name: 'Search',
          component: () => import('../components/search.vue'),
      },
      {
          path: '/websocket',
          name: 'WebSocket',
          component: () => import('../components/webscot.vue'),

      },
      {
          path: '/service',
          name: 'Service',
          component: () => import('../components/service.vue'),
      },
      {
          path: '/service1',
          name: 'Service1',
          component: () => import('../components/service1.vue'),
      },
      {
          path: '/chatuser',
          name: 'ChatUser',
          component: () => import('../components/chatuser.vue'),
      },
      {
          path: '/chatservice',
          name: 'ChatService',
          component: () => import('../components/chatservice.vue'),
          props: true // 将 route.params 作为 props 传递

      },
      {
          path: '/chat',  // 客服登录和用户列表
          name: 'Chat',
          component: () => import('../components/chat.vue'),
      },
      {
          path: '/user',
          name: 'User',
          component: () => import('../components/user.vue'),
      },
      {
          path: '/customer',
          name: 'Customer',
          component: () => import('../components/customer.vue'),
      },

      
      
      ]
})

// vue白名单过滤
// router.beforeEach((to, from, next) => {
//     var reslist = ['/','/index']
//     if (reslist.indexOf(to.path) == -1) { 
//         var menulist = localStorage.getItem('urldata')
//         if (menulist) { 
//             var mlist = JSON.parse(menulist)
//             if (mlist.indexOf(to.path) >= 0) { 
//                 next()
//             } else {
//                 alert('无权限访问')
//                 next({"name":"Login"})
//              }
//         } else {
//             alert('无权访问')
//         }


//     }
//     next()
// })




export default router